/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package knowledgebase.service;

import knowledgebase.dao.AuthenticationDAO;
import knowledgebase.model.User;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;

/**
 *
 * @author eugene
 */
@Service("userDetailsService")
public class UserDetailsServiceImpl implements UserDetailsService {

    private AuthenticationDAO dao;
    private Assembler assembler;

    public void setDao(AuthenticationDAO dao) {
        this.dao = dao;
    }

    @Override
    public UserDetails loadUserByUsername(String userName) throws UsernameNotFoundException {
        User userEntity = dao.findUserByName(userName);
        if (userEntity == null) {
            throw new UsernameNotFoundException("user not found");
        }
        org.springframework.security.core.userdetails.UserDetails user = new Assembler(userEntity);
        return user;
    }
}
